package com.itheima.app.manager;

import com.itheima.app.interceptor.UserHolder;
import com.itheima.domain.mongo.Video;
import com.itheima.service.mongo.VideoService;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class MQVideoManager {

    public static final Integer VIDEO_PUBLISH = 1;// 发视频
    public static final Integer VIDEO_LIKE = 2;// 点赞
    public static final Integer VIDEO_DISLIKE = 3;// 取消点赞
    public static final Integer VIDEO_COMMENT = 4;// 评论视频

    @Reference
    private VideoService videoService;
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    public void sendVideoMsg(String videoId,Integer type){
      Video video= videoService.findVideoById(videoId);
      if (video!=null) {
          Map map = new HashMap();
          map.put("vid", video.getVid().toString());
          map.put("userId", UserHolder.getId());
          map.put("type", type.toString());
          rocketMQTemplate.convertAndSend("tanhua-recommend-video", map);
      }
    }
}
